package com.lz.manage.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lz.common.annotation.Log;
import com.lz.common.core.controller.BaseController;
import com.lz.common.core.domain.AjaxResult;
import com.lz.common.enums.BusinessType;
import com.lz.manage.model.domain.TagInfo;
import com.lz.manage.model.vo.tagInfo.TagInfoVo;
import com.lz.manage.model.dto.tagInfo.TagInfoQuery;
import com.lz.manage.model.dto.tagInfo.TagInfoInsert;
import com.lz.manage.model.dto.tagInfo.TagInfoEdit;
import com.lz.manage.service.ITagInfoService;
import com.lz.common.utils.poi.ExcelUtil;
import com.lz.common.core.page.TableDataInfo;

/**
 * 标签信息Controller
 *
 * @author YY
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/manage/tagInfo")
public class TagInfoController extends BaseController
{
    @Resource
    private ITagInfoService tagInfoService;

    /**
     * 查询标签信息列表
     */
    @PreAuthorize("@ss.hasAnyPermi('manage:tagInfo:list,manage:tagInfo:query')")
    @GetMapping("/list")
    public TableDataInfo list(TagInfoQuery tagInfoQuery)
    {
        TagInfo tagInfo = TagInfoQuery.queryToObj(tagInfoQuery);
        startPage();
        List<TagInfo> list = tagInfoService.selectTagInfoList(tagInfo);
        List<TagInfoVo> listVo= list.stream().map(TagInfoVo::objToVo).collect(Collectors.toList());
        TableDataInfo table = getDataTable(list);
        table.setRows(listVo);
        return table;
    }

    /**
     * 导出标签信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:tagInfo:export')")
    @Log(title = "标签信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TagInfoQuery tagInfoQuery)
    {
        TagInfo tagInfo = TagInfoQuery.queryToObj(tagInfoQuery);
        List<TagInfo> list = tagInfoService.selectTagInfoList(tagInfo);
        ExcelUtil<TagInfo> util = new ExcelUtil<TagInfo>(TagInfo.class);
        util.exportExcel(response, list, "标签信息数据");
    }

    /**
     * 获取标签信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:tagInfo:query')")
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId)
    {
        TagInfo tagInfo = tagInfoService.selectTagInfoByTagId(tagId);
        return success(TagInfoVo.objToVo(tagInfo));
    }

    /**
     * 新增标签信息
     */
    @PreAuthorize("@ss.hasPermi('manage:tagInfo:add')")
    @Log(title = "标签信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TagInfoInsert tagInfoInsert)
    {
        TagInfo tagInfo = TagInfoInsert.insertToObj(tagInfoInsert);
        return toAjax(tagInfoService.insertTagInfo(tagInfo));
    }

    /**
     * 修改标签信息
     */
    @PreAuthorize("@ss.hasPermi('manage:tagInfo:edit')")
    @Log(title = "标签信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TagInfoEdit tagInfoEdit)
    {
        TagInfo tagInfo = TagInfoEdit.editToObj(tagInfoEdit);
        return toAjax(tagInfoService.updateTagInfo(tagInfo));
    }

    /**
     * 删除标签信息
     */
    @PreAuthorize("@ss.hasPermi('manage:tagInfo:remove')")
    @Log(title = "标签信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagIds}")
    public AjaxResult remove(@PathVariable Long[] tagIds)
    {
        return toAjax(tagInfoService.deleteTagInfoByTagIds(tagIds));
    }
}
